package com.dc.zuul.responsibility.factory;

import com.dc.core.utils.SpringContextUtils;
import com.dc.zuul.responsibility.GatewayHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: KEYD
 * @Date: 2020/1/19 12:12
 * @Desc: 使用工厂获取Handler
 */
public class FactoryHandler {

    /**
     * 责任链的启动方式
     * 方式一：1、将每个Handler存放到集合中实现遍历
     * 方式二：2、
     *
     * @return
     */
    public static List<GatewayHandler> getHandler() {
        //1、黑名单判断
        GatewayHandler blackListHandler = (GatewayHandler) SpringContextUtils.getBean("blackListHandler");
        //2、api验证签名
        GatewayHandler apiAuthorityHandler = (GatewayHandler) SpringContextUtils.getBean("apiAuthorityHandler");
        //3、api验证接口
        GatewayHandler apiCheckTokenHandler = (GatewayHandler) SpringContextUtils.getBean("apiCheckTokenHandler");
        List<GatewayHandler> listHandler = new ArrayList<>();
        listHandler.add(blackListHandler);
        listHandler.add(apiAuthorityHandler);
        listHandler.add(apiCheckTokenHandler);
        return listHandler;
    }
}
